program Sunrise;

{$MODE OBJFPC}
// remove dot for logging
{.DEFINE LOG}

uses
  // Free Pascal units
  Windows, SysUtils,
  // S2DE units
  S2DMain, S2DTypes, S2DSWCanvas;

// khoi tao vi tri cua lens
const LenPos: array[1..16] of Integer=
        (-1110, -666, 0, 1087, 1221, 1309, 1776, 2197,
          2819, 3130, 3220, 3263, 3663, 3707, 4440, 5125);

var Back     : TBuffer;
    Lens     : array[1..16] of TBuffer;
    X, Y     : LongInt;
    I        : Byte;

begin
  // nap resources
  LoadBMP(Back, 'Images\Scene.bmp');
  for I:= 1 to 16 do
    LoadBMP(Lens[I], 'Images\Lens-'+IntToStr(I)+'.bmp');
  Randomize;
  InitWindow(800, 600);
  ShowCursor(FALSE);

  // vong lap chinh cua chuong trinh
  repeat
    SwapBuffer(Screen, Back);
    SubBar(Screen, 0, 0, 799, 599, RGBToDWord(0, Round(((MouseY)/599)*64),
                                                 Round(((MouseY)/599)*64)));
    for I:= 1 to 16 do begin
      X:= (400+((400-MouseX)*
          (LenPos[I]-2280) div 2280))-Lens[I].Width shr 1;
      Y:= (300+((300-MouseY)*
          (LenPos[i]-2280) div 2280))-Lens[I].Height shr 1;
      AddBuffer(Screen, Lens[I], X, Y);
    end;

    // shows FPS & memory usage ra man hinh
    SysText(Screen, 10, 10, 'FPS        : '+IntToStr(S2DInfo.FPS), $FFFFFF);
    SysText(Screen, 10, 20, 'Memory used: '+IntToStr(S2DInfo.TotalAllocMemory)+' bytes', $FFFFFF);
    GetMessages;
  until NOT S2DInfo.Running OR KeyMap[VK_ESCAPE];
  for I:= 16 downto 1 do
  // giai phong resource va thoat
  FreeBuffer(Lens[I]);
  FreeBuffer(Back);
  S2DMain.CloseWindow;
end.




